package com.beadhouse.nurlevel.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.beadhouse.common.dto.JSONResponse;
import com.beadhouse.common.dto.QueryResult;
import com.beadhouse.entity.NurLevelEntity;
import com.beadhouse.nurlevel.ao.AddNurLevelAO;
import com.beadhouse.nurlevel.ao.UpdateNurLevelAO;
import com.beadhouse.nurlevel.service.NurLevelService;

@Controller
@RequestMapping("/api/nurlevel")
public class NurLevelController {
	@Autowired 
	NurLevelService nlService;
	
	@GetMapping("/add")
	public String addNurLeve(AddNurLevelAO ao) throws Exception {
		nlService.addNurLevel(ao);
		return "forward:/api/nurlevel/selectList";
	}
	@GetMapping("/delete")
	public String delNurLevel(Integer levelId) throws Exception  {
		nlService.delNurLevel(levelId);
		return "forward:/api/nurlevel/selectList";
	}
	@GetMapping("/selectList")
	public ModelAndView queryNurLevel(Integer pageNum,String key) throws Exception {
		ModelAndView mav=new ModelAndView();
		if(pageNum==null) {
				pageNum=1;
			}
		QueryResult<NurLevelEntity> list=nlService.selectLike(pageNum, key);
		mav.setViewName("nurlevel/nurlevel");
		mav.addObject("data",list);
		return mav;
	}
	
	@PostMapping("/select")
	@ResponseBody
	public JSONResponse select(Integer levelId) throws Exception {
		NurLevelEntity r=nlService.selectOne(levelId);
		return JSONResponse.ok(r);
	}
	
	@GetMapping("/update")
	public String updateNurLevel(UpdateNurLevelAO ao) throws Exception {
			int currentUserId=0;
			nlService.updateNurLevel(currentUserId, ao);
			return "forward:/api/nurlevel/selectList";
	}
}
